package com.hrp.service;

import com.hrp.domain.TransportRecord;
import com.hrp.hrpdao.TransportRecordQueryDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2019-04-29.
 */
@Service
public class TransportRecordQueryService {

    private static final Logger logger = LoggerFactory.getLogger(TransportRecordService.class);

    @Autowired
    private TransportRecordQueryDao transportRecordQueryDao;

    public Map<String, Object> getTransportRecordByPage(Integer page, Integer rows,String sort, String order,String sendTimeKsrq,String sendTimeJsrq,String varietiesIdStr,String supplierIdStr,String receiverIdStr) {

        Map<String,String> params = new HashMap<>();
        params.put("page",""+page+"");
        params.put("rows",""+rows+"");
        params.put("sort",""+sort+"");
        params.put("order",""+order+"");
        params.put("sendTimeKsrq",""+sendTimeKsrq+"");
        params.put("sendTimeJsrq",""+sendTimeJsrq+"");
        params.put("varietiesIdStr",""+varietiesIdStr+"");
        params.put("supplierIdStr",""+supplierIdStr+"");
        params.put("receiverIdStr",""+receiverIdStr+"");




        Map<String, Object> jsonMap = new HashMap<String, Object>();//定义map
        try{
            //Integer total = transportRecordQueryDao.getTotalCount();
            //List<Jxkhzq> list = jxkhzqDao.getJxkhzqByPage(10,20);

            List<Map<String,String>>  lists = transportRecordQueryDao.getTransportRecordByPageForProc(params);


            jsonMap.put("total", lists.get(0).get("taotalCount"));//total键 存放总记录数，必须的
            jsonMap.put("rows", lists);//rows键 存放每页记录 list
            return jsonMap;
        }catch (Exception e) {
            e.printStackTrace();
            logger.info("获取分页账期数据失败");
            return jsonMap;
        }
    }


    public Map<String,Object> getTransportRecordByPageSummary(Integer page, Integer rows, String sort, String order, String sendTimeKsrq, String sendTimeJsrq,String varietiesIdStr, String supplierIdStr, String receiverIdStr) {

        Map<String,String> params = new HashMap<>();
        params.put("page",""+page+"");
        params.put("rows",""+rows+"");
        params.put("sort",""+sort+"");
        params.put("order",""+order+"");
        params.put("sendTimeKsrq",""+sendTimeKsrq+"");
        params.put("sendTimeJsrq",""+sendTimeJsrq+"");
        params.put("varietiesIdStr",""+varietiesIdStr+"");
        params.put("supplierIdStr",""+supplierIdStr+"");
        params.put("receiverIdStr",""+receiverIdStr+"");




        Map<String, Object> jsonMap = new HashMap<String, Object>();//定义map
        try{
            //Integer total = transportRecordQueryDao.getTotalCount();
            //List<Jxkhzq> list = jxkhzqDao.getJxkhzqByPage(10,20);

            List<Map<String,String>>  lists = transportRecordQueryDao.getTransportRecordByPageSummary(params);


            jsonMap.put("total", lists.get(0).get("taotalCount"));//total键 存放总记录数，必须的
            jsonMap.put("rows", lists);//rows键 存放每页记录 list
            return jsonMap;
        }catch (Exception e) {
            e.printStackTrace();
            logger.info("获取分页账期数据失败");
            return jsonMap;
        }
    }
}
